package com.idealighter.game.games.errenniuniu.struct;

import com.idealighter.game.core.common.Game;
import com.idealighter.game.dictionary.domain.ErrenniuniuRoomDomain;
import com.idealighter.game.games.common.AbstractRoom;
import com.idealighter.game.games.common.AbstractSeat;
import com.idealighter.game.games.common.AbstractTable;
import com.idealighter.game.games.errenniuniu.manager.ErRenNiuNiuDataMgr;
import com.idealighter.game.server.context.ApplicationContext;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 二人牛牛房间 .
 * 
 * @date 2015年9月15日 下午7:47:06
 *
 */
public class ErRenNiuNiuRoom extends AbstractRoom {

  // 桌子
  public final Map<Integer, ErRenNiuNiuTable> tables;

  public ErRenNiuNiuRoom(ErrenniuniuRoomDomain roomDomain) {
    super(roomDomain.getId(), roomDomain.getName());
    this.tables = createTables(roomDomain.getTable());
  }

  /**
   * 创建桌子 .
   * 
   * @param tableNum .
   * @return
   */
  private Map<Integer, ErRenNiuNiuTable> createTables(int tableNum) {
    Map<Integer, ErRenNiuNiuTable> tables = new LinkedHashMap<>();
    for (int i = 0; i < tableNum; i++) {
      int tableId = id.intValue() * AbstractTable.MAX_TABLE + i + 1;
      tables.put(tableId, new ErRenNiuNiuTable(tableId, this));
    }

    return tables;
  }

  @Override
  public Game game() {
    return Game.ERREN_NIUNIU;
  }

  @Override
  public AbstractSeat seat(long playerId) {
    return ApplicationContext.getBean(ErRenNiuNiuDataMgr.class).getPlayerSeat(playerId);
  }

  @Override
  public Collection<ErRenNiuNiuTable> tables() {

    return tables.values();
  }

}
